import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer;

public class bytedance_夏季特惠 {
    public static int MAXN = 501;
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();
    public static int[][] arr = new int[MAXN][2];
    public static int cnt;
    public static void main1(String[] args) throws IOException {
        int n = in.nextInt();
        int sum = in.nextInt();
        long ret = 0;
        cnt = 1;
        for (int i = 0,a,b,c; i < n; i++) {
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            if (a - 2 * b >= 0) {
                ret += c;
                sum += a - 2 * b;
            } else {
                arr[cnt][0] = 2 * b - a;
                arr[cnt++][1] = c;
            }
        }
        long[][] dp = new long[cnt + 1][sum + 1];
        for (int i = 1; i <= cnt; i++) {
            for (int j = 0; j <= sum; j++) {
                dp[i][j] = dp[i - 1][j];
                if (j - arr[i][0] >= 0) {
                    dp[i][j] = Math.max(dp[i][j],dp[i - 1][j - arr[i][0]] + arr[i][1]);
                }
            }
        }
        System.out.println(ret + dp[cnt][sum]);
    }













    public static class Read {
        StringTokenizer st = new StringTokenizer("");
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String next() throws IOException {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(bf.readLine());
            }
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
    }
}
